<template>
  <div>
    <div style=" padding: 20px;">
      <a-row :gutter="24">
        <a-col :span="24" class="someSpace">
          <a-card class="cardShadow" title="">
            <a-spin :spinning="confirmLoading">
              <a-row class="cTradeTitle">
                <h2>2022年度重点用能单位能源利用状况报告及温室气体排放报告</h2>
              </a-row>
              <a-form :form="form">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="上报率">
                  <a-input v-decorator="['sbl1', {
            rules: [
              {
                required: true,
                message: '上报率必须为小于100的正数，最多包含两位小数!',
                 pattern: /^(100\.00|100|100\.0|\d{1,2}(\.\d{1,2})?)$/
              },
            ],
            }]" placeholder="请输入上报率" suffix="%" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="企业总数">
                  <a-input v-decorator="['qyzs1', {
            rules: [
              {
                required: true,
                message: '企业总数必须必须为正整数!',
                pattern: /^\d+$/
              },
            ],
            }]" placeholder="请输入企业总数" suffix="家" />
                </a-form-item>
              </a-form>
              <a-row class="cTradeTitle">
                <h2>2022年度碳交易纳管企业碳排放报告</h2>
              </a-row>
              <a-form :form="form">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="上报率">
                  <a-input v-decorator="['sbl2', {
            rules: [
              {
                required: true,
                message: '上报率必须为小于100的正数，最多包含两位小数!',
                 pattern: /^(100\.00|100|100\.0|\d{1,2}(\.\d{1,2})?)$/
              },
            ],
            }]" placeholder="请输入上报率" suffix="%" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="企业总数">
                  <a-input v-decorator="['qyzs2', {
            rules: [
              {
                required: true,
                message: '企业总数必须必须为正整数!',
                pattern: /^\d+$/
              },
            ],
            }]" placeholder="请输入企业总数" suffix="家" />
                </a-form-item>
              </a-form>
              <a-row class="cTradeTitle">
                <h2>2022年度上海市重点用能单位能耗在线监测系统</h2>
              </a-row>
              <a-form :form="form">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="重点用能单位接入率">
                  <a-input v-decorator="['jrl', {
            rules: [
              {
                required: true,
                message: '重点用能单位接入率必须为小于100的正数，最多包含两位小数!',
                 pattern: /^(100\.00|100|100\.0|\d{1,2}(\.\d{1,2})?)$/
              },
            ],
            }]" placeholder="请输入重点用能单位接入率" suffix="%" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="接入数量">
                  <a-input v-decorator="['jrsl', {
            rules: [
              {
                required: true,
                message: '接入数量必须必须为正整数!',
                pattern: /^\d+$/
              },
            ],
            }]" placeholder="请输入接入数量" suffix="家" />
                </a-form-item>
              </a-form>
              <a-button :loading="confirmLoading" class="button" icon="upload" type="primary" @click="handleOk()">提交
              </a-button>
            </a-spin>
          </a-card>
        </a-col>
      </a-row>
    </div>
  </div>
</template>

<script>
import { getAction, httpAction } from '@api/manage'
import pick from 'lodash.pick'

export default {
  name: 'companyMiddle',
  data() {
    return {
      model: '',
      confirmLoading: false,
      title: '',
      visible: false,
      form: this.$form.createForm(this),
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      url: {
        list: '',
        edit: '/carbon/enterpriseFileData/edit'
      }
    }
  },
  methods: {
    getData() {
      let that = this
      let httpurl = '/carbon/enterpriseFileData/list'
      httpAction(httpurl, {}, 'get').then(res => {
        if (res.success) {
          this.model = res.result.records[0]
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(
              this.model,
              'sbl1',
              'sbl2',
              'qyzs1',
              'qyzs2',
              'jrl',
              'jrsl'
            ))
          })
        }
      })
    },
    handleOk() {
      let that = this
      this.form.validateFields((err, values) => {
        if (!err) {
          let httpurl = ''
          let method = ''
          this.confirmLoading = true
          let formData = Object.assign(this.model, values)
          httpurl += this.url.edit
          method = 'put'
          httpAction(httpurl, formData, method).then(res => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('refresh')
            } else {
              that.$message.error(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    }
  },
  mounted() {
    this.getData()
  }
}
</script>

<style lang="stylus" scoped>
.cardShadow {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
}

.verticalCenter {
  //  垂直居中
}

.someSpace {
  margin-bottom: 24px;
}

.cTradeTitle {
  background-color #eeeeee
  padding-left 20px
  padding-top 8px
  margin-bottom 30px
  margin-top 10px
}

.button {
  margin-left: 50%;
  transform: translateX(-50%);
}
</style>